package com.example.controller.note;

import com.alibaba.fastjson.JSONObject;
import com.example.config.auth.SecurityUtil;
import com.example.domain.vo.NoteVo;
import com.example.ribbon.service.NoteRibbonService;
import com.example.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/note")
public class NoteController {

    @Autowired
    private NoteRibbonService noteRibbonService;

    @PostMapping("/saveorupdate")
    public JSONObject saveOrUpdateNote(@RequestBody @Validated NoteVo vo) {
        if(vo.getId()==null){
            return noteRibbonService.noteUserSave(vo.getTitle(), vo.getTypeId(), vo.getTag(),vo.getContent());
        }else {
            return noteRibbonService.noteUserUpdate(vo.getId(), vo.getTitle(), vo.getTypeId(), vo.getTag(),vo.getContent());
        }
    }

    @GetMapping("/getone")
    public JSONObject getNoteOne(@RequestParam("noteId")String noteId,
                                 @RequestParam("nodeId")String nodeId) {
        return noteRibbonService.noteGetOne(nodeId, noteId);
    }

    @GetMapping("/getoneinfo")
    public JSONObject getNoteOneInfo(@RequestParam("noteId")String noteId,
                                     @RequestParam("nodeId")String nodeId) {
        return noteRibbonService.noteGetOneInfo(nodeId, noteId);
    }

    @GetMapping("/page")
    public JSONObject page(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                           @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                           @RequestParam(value = "keyword",required = false)String keyword) {
        String userId= SecurityUtil.getUserId();
        return noteRibbonService.notePageUser(userId,pageNum,pageSize,keyword);
    }

}
